<template>
	<view>
		<view class="card" v-for="(item, index) in tableList" :key="index" @click="viewArticle(item)">
			<view class="text-container">
				<view class="title">
					<h3>{{ item.articleTitle }}</h3>
				</view>
				<view class="time">
					<p>{{ item.createTime }}</p>
				</view>
			</view>
			<view class="image-container">
				<!-- <img src="../../static/images/banner/banner01.jpg" alt="Construction" /> -->
			</view>
		</view>
		<view>
			<u-loadmore @loadmore="loadmore" :status="status" />
		</view>
	</view>
</template>

<script>
	import {
		safeThreeOnelist
	} from "@/api/article/index";
	export default {
		data() {
			return {
				status: "loadmore",
				tableList: [],
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 5,

				},
				total: 0,
			};
		},
		onLoad() {
			this.loadmore();
		},
		mounted() {
			this.list();
		},
		methods: {
			//点击查看文章内容
			viewArticle(item) {
				uni.navigateTo({
					url: `/pages/index/components/informationCenterDetail?id=${item.articleContentId}`,
				});
			},
			async list() {
				uni.showLoading({
					title: "加载中...",
					mask: true, // 遮罩层
				});
				try {
					const {
						rows,
						code,
						msg,
						total
					} = await safeThreeOnelist(
						this.queryParams
					);
					if (code == 200) {
						// 将新加载的数据追加到现有的 tableList 中
						this.tableList = this.tableList.concat(rows);
						this.total = total;
						if (this.tableList.length == total) {
							this.status = "nomore";
						}
					}
				} catch (error) {
					uni.showToast({
						title: "加载数据时出错",
						icon: "none",
					});
				} finally {
					// 确保在加载完成后隐藏 loading
					uni.hideLoading();
				}
			},

			loadmore() {
				this.queryParams.pageNum++;
				this.list();
			},
		},
	};
</script>

<style lang="scss">
	.card {
		display: flex;
		border: 1px solid #ddd;
		overflow: hidden;
		height: 200rpx;
	}

	.image-container {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.image-container img {
		width: 100%;
		height: auto;
		border-radius: 30rpx 30rpx;
		width: 150rpx;
		height: 150rpx;
		object-fit: contain
			/* 圆角效果 */
	}

	.text-container {
		flex: 2;
		padding: 10px;
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		.title {
			color: #333333;
			font-size: 28rpx;
		}

		.time {
			color: #999999;
			font-size: 28rpx;
		}
	}
</style>